package com.moyun.search.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.moyun.search.common.result.PageVO;
import com.moyun.search.common.result.Result;
import com.moyun.search.common.result.ResultUtil;
import com.moyun.search.dao.mapper.ProjectInfoMapper;
import com.moyun.search.domain.ProjectInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 项目信息服务
 * @author: zealon
 * @since: 2021/12/24
 */
@Service
public class ProjectInfoService {

    @Autowired
    private ProjectInfoMapper projectInfoMapper;

    public ProjectInfo getById(Integer id){
        return this.projectInfoMapper.selectById(id);
    }

    public Result details(Integer id){
        ProjectInfo project = this.getById(id);
        return ResultUtil.success(project);
    }

    public PageVO<ProjectInfo> getListData(Integer limit, Integer page, Integer categoryId){
        if (categoryId != null && categoryId == 0) {
            categoryId = null;
        }
        PageHelper.startPage(page, limit);
        Page<ProjectInfo> pageList = (Page<ProjectInfo>) this.projectInfoMapper.findPageWithResult(categoryId);
        return new PageVO<>(pageList.getTotal(), 0,"",pageList);
    }
}
